import 'package:demo/tools/tools_storage.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:demo/views/base/base_controller.dart';
import 'package:demo/tools/tools_sqlite.dart';
import 'package:demo/component/component_contact.dart';

class GroupInviteController extends BaseController {
  String userId = ToolsStorage().local().userId;
  // 联系人列表
  List<ContactModel> dataList = [];
  // 选中列表
  List<String> selectList = [];
  // 初始化
  void getList() async {
    // 好友列表
    List<ChatFriend> friendList = await ToolsSqlite().friend.getList();
    // 转换
    for (var friend in friendList) {
      if (friend.userId == userId) {
        continue;
      }
      dataList.add(
        ContactModel(
          userId: friend.userId,
          nickname: friend.nickname,
          portrait: friend.portrait,
          remark: friend.remark,
          extend: 'ID：${friend.userNo}',
        ),
      );
    }
    update();
  }

  // 邀请
  Future<void> invite() async {
    // 提醒
    EasyLoading.showToast('操作成功');
    // 返回
    Get.back();
  }

  @override
  void onInit() {
    super.onInit();
    getList();
  }
}
